package org.example.controller.impl;

import org.example.controller.MenuController;
import org.example.domain.response.ResponseResult;
import org.example.services.impl.MenuServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/menus")
public class MenuControllerImpl implements MenuController {

    @Autowired
    private MenuServiceImpl menuService;

    @Override
    @GetMapping
    public ResponseResult getAllMenus() {
        return menuService.getAllMenus();
    }

    @Override
    @GetMapping("/{roleId}")
    @PreAuthorize("hasAuthority('menu:select')")
    public ResponseResult getMenusByRoleId(@PathVariable int roleId) {
        return menuService.getMenusByRoleId(roleId);
    }

    @Override
    @PutMapping("/{roleId}")
    @PreAuthorize("hasAuthority('menu:update')")
    public ResponseResult updateRoleMenus(@PathVariable int roleId,@RequestBody List<Integer> menuList) {
        return menuService.updateRoleMenus(roleId,menuList);
    }

    @Override
    @DeleteMapping("/{roleId}")
    @PreAuthorize("hasAuthority('menu:delete')")
    public ResponseResult deleteRoleMenus(@PathVariable int roleId) {
        return menuService.deleteRoleMenus(roleId);
    }
}


